package cn.vcjf.washcar.userInfo.controller;


import cn.vcjf.washcar.common.web.TableResult;
import cn.vcjf.washcar.userInfo.entity.UserAddress;
import cn.vcjf.washcar.userInfo.service.UserAddressService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-07-18
 */
@Controller
@RequestMapping("/userInfo/userAddress")
public class UserAddressController {
	@Resource
	private UserAddressService userAddressService;

	@RequestMapping("/addUserAddress")
	@ResponseBody
	public TableResult addUserAddress(UserAddress userAddress) {
		userAddress.preInsert();
		boolean b = userAddressService.insert(userAddress);
		return TableResult.Result(b);
	}

	@RequestMapping("/updateUserAddress")
	@ResponseBody
	public TableResult updateUserAddress(UserAddress userAddress) {
		userAddress.preUpdate();
		boolean b = userAddressService.updateById(userAddress);
		return TableResult.Result(b);
	}

	@RequestMapping("/findUserAddressOne")
	@ResponseBody
	public TableResult findUserAddressOne(UserAddress userAddress) {

		EntityWrapper<UserAddress> wrapper = userAddress.getQueryWrapper();

		UserAddress result = userAddressService.selectOne(wrapper);

		return TableResult.Result(result);
	}

	@RequestMapping("/findUserAddressList")
	@ResponseBody
	public TableResult findUserAddressList(UserAddress userAddress) {

		EntityWrapper<UserAddress> wrapper = userAddress.getQueryWrapper();

		Page<UserAddress> page = userAddress.getPageInfo();
		wrapper.orderBy("createTime", false);
		page = userAddressService.selectPage(page, wrapper);

		return TableResult.Result(page);

	}

	@RequestMapping("/deleteUserAddress")
	@ResponseBody
	public TableResult deleteUserAddress(UserAddress userAddress) {
		userAddress.preUpdate();
		boolean b = userAddressService.deleteById(userAddress.getId());
		return TableResult.Result(b);
	}

}
